<template>
  <div class="boss-header">
      <div class="header-container">
        <div class="logo">
          <router-link to="/home" @click.native="refreshHome">BOSS直聘</router-link>
        </div>

        <!-- 新城市选择弹窗按钮 -->
        <div class="city-selector-btn" @click="showSelector = true">
          <i class="location-icon"></i>
          <span class="current-city">{{ currentCity }}</span>
          <span class="switch-text">[切换]</span>
        </div>
        <CitySelector v-model:visible="showSelector" @select="onSelectCity" />

        <nav class="main-nav">
          <ul>
            <li><router-link to="/home" active-class="active" exact>首页</router-link></li>
            <li><router-link to="/jobList" active-class="active">职位</router-link></li>
            <li><router-link to="/companyList" active-class="active">公司</router-link></li>
            <li class="combo-item">
              <router-link to="/school" active-class="active">校园</router-link>
              <span class="divider">/</span>
              <router-link to="/overseas" active-class="active">海归</router-link>
            </li>
            <li><router-link to="/app" active-class="active">APP</router-link></li>
            <li><router-link to="/discover" active-class="active">社区</router-link></li>
            <li><router-link to="/overseas" active-class="active">海外</router-link></li>
            <li><router-link to="/accessible" active-class="active">无障碍专区</router-link></li>
          </ul>
        </nav>

        <div class="user-area">
          <!-- 消息按钮 -->
          <div class="message-box" @mouseenter="showMessageTip = true" @mouseleave="showMessageTip = false">
            <a href="/messages" class="message-btn">
              <i class="message-icon"></i>
              <span class="message-count" v-if="unreadCount > 0">{{ unreadCount }}</span>
            </a>
            <div class="message-tip" v-show="showMessageTip">
              <div class="tip-arrow"></div>
              <div class="tip-content">您有{{ unreadCount }}条未读消息</div>
            </div>
          </div>

          <!-- 简历按钮 -->
          <div class="resume-box" @mouseenter="showResumeMenu = true" @mouseleave="showResumeMenu = false">
            <a href="/resume" class="resume-btn">简历</a>
            <div class="resume-menu" v-show="showResumeMenu">
              <a href="/resume/edit" class="menu-item">
                <i class="resume-icon edit-icon"></i>
                <span>在线编辑简历</span>
              </a>
              <a href="/resume/upload" class="menu-item">
                <i class="resume-icon upload-icon"></i>
                <span>上传附件简历</span>
              </a>
              <a href="/resume/template" class="menu-item">
                <i class="resume-icon template-icon"></i>
                <span>简历模板</span>
              </a>
            </div>
          </div>

          <!-- 用户头像 -->
          <div class="user-avatar" @click="toggleUserMenu">
            <span>B</span>
            <div class="user-menu" v-show="showUserMenu">
              <a href="/emp">个人中心</a>
              <a href="/verify-process">账号设置</a>
              <a href="/">退出登录</a>
            </div>
          </div>
        </div>
      </div>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import CitySelector from './CitySelector.vue'

const currentCity = ref('北京')
const showSelector = ref(false)
const unreadCount = ref(3)
const showMessageTip = ref(false)
const showResumeMenu = ref(false)
const showUserMenu = ref(false)
let userMenuTimer = null

const toggleUserMenu = () => {
  showUserMenu.value = !showUserMenu.value
}
const onSelectCity = (city) => {
  currentCity.value = city
}
function onUserMenuLeave() {
  userMenuTimer = setTimeout(() => {
    showUserMenu.value = false
  }, 100)
}

const refreshHome = () => {
  if (window.location.pathname === '/home') {
    window.location.reload()
  }
}
</script>

<style scoped>
.boss-header {
  background-color: #202329;
  color: white;
  height: 49px;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
  background-image: url('https://img.bosszhipin.com/static/zhipin/geek/982401352937125536.png.webp');
  background-size: 100% 49px;
  background-repeat: no-repeat;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.header-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
}
.logo a {
  color: #00BEBD;
  font-size: 22px;
  font-weight: bold;
  text-decoration: none;
  margin-right: 30px;
}
.city-selector-btn {
  position: relative;
  margin-right: 30px;
  cursor: pointer;
  padding: 0 10px;
  height: 100%;
  display: flex;
  align-items: center;
}
.city-selector-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}
.location-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FFFFFF"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg>');
  background-repeat: no-repeat;
  margin-right: 5px;
}
.current-city {
  font-size: 14px;
  color: #FFFFFF;
}
.switch-text {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin-left: 4px;
}
.main-nav ul {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}
.main-nav li {
  margin: 0 10px;
  position: relative;
}
.main-nav a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 14px;
  padding: 15px 5px;
  display: inline-block;
  transition: all 0.3s;
}
.main-nav a:hover,
.main-nav a.active {
  color: #FFFFFF;
  font-weight: 500;
}
.combo-item {
  display: flex;
  align-items: center;
}
.divider {
  color: rgba(255, 255, 255, 0.3);
  margin: 0 2px;
}
.user-area {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 20px;
}
.message-box {
  position: relative;
}
.message-btn {
  display: flex;
  align-items: center;
  position: relative;
}
.message-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FFFFFF"><path d="M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z"/></svg>');
  background-repeat: no-repeat;
}
.resume-box {
  position: relative;
}
.resume-btn {
  color: #fff;
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  padding: 0 10px;
  height: 100%;
  display: flex;
  align-items: center;
}
.resume-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: #fff;
  color: #333;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  min-width: 140px;
  padding: 8px 0;
  z-index: 10;
  display: none;
}
.resume-box:hover .resume-menu,
.resume-menu:active {
  display: block;
}
.menu-item {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  color: #333;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.menu-item:hover {
  background: #f5f7fa;
  color: #00BEBD;
}
.resume-icon {
  margin-right: 8px;
}
.user-avatar {
  width: 32px;
  height: 32px;
  background: #00BEBD;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  position: relative;
}
.user-menu {
  position: absolute;
  top: 110%;
  right: 0;
  background: #fff;
  color: #333;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  min-width: 120px;
  padding: 8px 0;
  z-index: 10;
  display: none;
}
.user-avatar:hover .user-menu,
.user-menu:active {
  display: block;
}
.user-menu a {
  display: block;
  padding: 8px 16px;
  color: #333;
  text-decoration: none;
  font-size: 14px;
}
.user-menu a:hover {
  background: #f5f7fa;
  color: #00BEBD;
}
.message-count {
  background: #FF7D00;
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  padding: 2px 6px;
  margin-left: 4px;
  position: absolute;
  top: -8px;
  right: -8px;
}
.message-tip {
  position: absolute;
  top: 36px;
  left: 0;
  background: #fff;
  color: #333;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  padding: 8px 16px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.tip-arrow {
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid #fff;
  position: absolute;
  top: -8px;
  left: 16px;
}
.tip-content {
  font-size: 13px;
  color: #333;
}
</style> 